 Ext.onReady(function(){
 	var loginAction = function(){
 		var f = Ext.getCmp("loginForm").getForm();
        if(f.isValid()){
            f.submit({
                clientValidation: true,
                url: contextPath + "/auth/loginAction",
                success: function(form, action) {
                    var result = action.result;
                    if(result.success)
                       window.location.href=contextPath + result.resultUrl;
                    else
                       Ext.Msg.alert('提示', result.message);
                },
                failure: function(form, action) {
                    var result = action.result;
                    Ext.Msg.alert('提示', result.message);
                }
            });
        }
 	};
    var win = Ext.create("Ext.window.Window",{
        title:'登录',
        layout:'fit',
        width:300,
        height:200,
        closable:false,
        animateTarget:Ext.getBody(),
        buttonAlign:'center',
        bodyStyle:'padding:5px',
        items:[{
            xtype:'form',
            id:'loginForm',
            border:false,
            frame:true,
            bodyStyle:'margin-top:35px;',
            defaultType:'textfield',
            defaults:{
            	autoScroll: true,
            	width:250
            },
            fieldDefaults: {
                labelAlign: 'right',
                labelWidth: 70,
                labelSeparator:':',
                maxLength:20,
                allowBlank:false
            },
            items:[{
                value:'shuyuan',
                fieldLabel:'用户名',
                name:'username',
                listeners : {
                    specialkey : function(field, e) {
                        if (e.getKey() == Ext.EventObject.ENTER) {
                            Ext.getCmp("password").focus();
                        }
                    }
                }
            },{
            	value:'000000',
                fieldLabel:'密码',
                name:'password',
                id:"password",
                inputType:'password',
                listeners : {
                    specialkey : function(field, e) {
                        if (e.getKey() == Ext.EventObject.ENTER) {
                            loginAction()
                        }
                    }
                }
            }]
        }],
        buttons:[{
            text:'登录',
            handler:function(){
            	loginAction();
            }
        },{
            text:'重置',
            handler:function(){
            	Ext.getCmp("loginForm").getForm().reset();
            }
        }]
    });
    win.show();
});